package com.situ.javase.week3.Day1;

import java.awt.GridLayout;

import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

	public class GridLayoutDemo {
		public static void main(String[] args) {
		//创建JFrame
		JFrame frame = new JFrame();
		frame.setTitle("9空格");
		JPanel panel = new JPanel();
		frame.add(panel);
		//设置布局
		panel.setLayout(new GridLayout(3,3));
		//创建组件
		JButton[] buttons = new JButton[9];
		for (int i = 0; i < buttons.length; i++) {
			buttons[i] = new JButton((i + 1)+ "" );
		}
		//添加组件
		for (int i = 0; i < buttons.length; i++) {
			panel.add(buttons[i]);
		}
		// 设置大小,单位是像素
	     frame.setSize(500, 500);
	     // 设置初始位置
	     frame.setLocation(500, 200);
	     // 默认是不显示
	     frame.setVisible(true);
	     // 关闭Frame(设置Frame默认关闭时候的操作，就是当关闭时候退出)
	     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		}
}
